<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" id="searchPrjNmId">
                <div class="label">项目名称</div>
                <div class="field">
                    <input name="prjNm" id="prjNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox" id="searchCstNmId">
                <div class="label">客户名称</div>
                <div class="field">
                    <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
             <div class="fieldBox" id="searchCstNmId">
                <div class="label">客户经理名称</div>
                <div class="field">
                    <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
             <div class="fieldBox" id="searchPrjTypCdId">
              <div class="label">项目类型</div>
                <div class="field">
                <select name="prjTypCd"  id="prjTypCd" >
                 <option value="  " selected="selected">--请选择--</option>
                 <c:forEach items="${projectTypeList}" var="opt">
                  <option value="${opt.key}">${opt.value}</option>
                 </c:forEach>
                </select>
                </div>
            </div>
            
           <div class="fieldBox" id="searchCntTypCdId">
            <div class="label">合同签署方式</div>
               <div class="field">
                 <select name="cntTypCd"  id="cntTypCd"  >
                  <option value="  " selected="selected">--请选择--</option>
                <c:forEach items="${cntTypCdList}" var="opt">
                 <option value="${opt.key}">${opt.value}</option>
                </c:forEach>
               </select>
               </div>
            </div>
         <div class="fieldBox" id="searchBizTypCdId">
            <div class="label">业务类型</div>
               <div class="field">
                 <select name="bizTypCd"  id="bizTypCd"  >
                  <option value="  " selected="selected">--请选择--</option>
                <c:forEach items="${bizTypeList}" var="opt">
                 <option value="${opt.key}">${opt.value}</option>
                </c:forEach>
               </select>
               </div>
            </div>
             <div class="fieldBox" id="searchLsCntNoId">
                <div class="label">合同号</div>
                <div class="field">
                    <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                </div>
            </div>
                <div class="fieldBox" id="searchBuOrgCdId">
                <div class="label">所属事业部</div>
                <div class="field">
                    <select name="buOrgCd" id="buOrgCd">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${orgListList }" var="org">
                        	<c:if test="${currentBuOrgCd == org.key }">
                        		<option value="${org.key }" selected>${org.value }</option>
                        	</c:if>
                        	<c:if test="${currentBuOrgCd != org.key }">
                        		<option value="${org.key }">${org.value }</option>
                        	</c:if>
                        </c:forEach>
                    </select>
                </div>
            </div>
                    <div class="fieldBox col_33" id="isDelId" >
                <div class="label">是否删除</div>
                <div class="field">
                    <select name="isDel"  id="isDel"  >
		                  <option value="0"  selected="selected">否</option>
		                 <option value="1">是</option>
	               </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="insCodeDiv">
                <div class="label">第三方机构</div>
                <div class="field">
                    <select name="insCode"  id="insCode" >
                        <option value="  " selected="selected">--请选择--</option>
                        <c:forEach items="${cancelInsCreditList}" var="fri">
                            <option value="${fri.key}">${fri.value}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
               <span style="color: red">删除之前请确认,谨慎操作！</span>
            </div>
            <!-- 隐藏客户ID, 提供给客户管理中 项目列表使用 -->
			<div class="fieldBox col_100" style="display:none;">
		       <div class="field">
		        	<input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
		        	<input name="fromPrjFlagNm" id="fromPrjFlagId" type="text" class="ui-textbox" value="${fromPrjFlag}">
		        	<input name="cstNmNm" id="cstNmId" type="text" class="ui-textbox" value="${cstNm}">
		       </div>
		    </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div> 
</div>

<div id="chooseFlowDIV" style="display:none">
    <div id="ligergrid_flowStart" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	var queryFlag = '${queryFlag}'; //只查询列表
    var cancelInsCreditList = '${cancelInsCreditList}'; //支持撤销资方授信的资管机构列表
    var cancelInsCodeCreditList = '${cancelInsCodeCreditList}'; //支持撤销资方授信的资管机构编码列表

	$(function () {
		if(queryFlag=="query"){
			//隐藏按钮
			$("#addBtn").hide();
			$("#flowStartBtn").hide();
			
		}
		//客户ID做为默认查询条件, 提供给客户管理中项目列表使用
		var _cstId = $("#cstId").val();
		var params = "";//默认条件
		if(StringUtils.isNotEmpty(_cstId)){
			params = "?cstId="+_cstId
		}
		var lnkCompId = '${lnkCompId}';
		if(StringUtils.isNotEmpty(lnkCompId)){
			$("#searchPrjStsCdId").hide();
			$("#searchPrjTypCdId").hide();
			$("#searchCstNmId").hide();
			$("#searchBizTypCdId").hide();
			$("#searchCntTypCdId").hide();
			
			$("#flowStartBtn").hide();
			$("#addBtn").hide();
		}
		var _splId = '${splId}';
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/project/prjbscinfo/initListForDelQuary.do'+params,
	    	method : 'get',
	    	parms:{
	    		splId:_splId,
	    		lnkCompId:lnkCompId
	    	},
	    	
	        columns: [
	             { display: '项目名称', name: 'prjNm', align:'left',minWidth: 140 ,
	            	render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
	            		},
	            	enabledSort:true}, 
	             { display: '合同号', name: 'lsCntNo', minWidth: 140 , enabledSort:true}, 
	            { display: '客户', name: 'cstNm', minWidth: 140,align:'center', enabledSort:true},
	            { display: '客户经理', name: 'cstMgrNm', minWidth: 140,align:'center', enabledSort:true},
	            { display: '所属机构', name: 'buOrgCdNm', width: 100 , enabledSort:true},
	            { display: '项目类型', name: 'prjTypCdNm', width: 150, enabledSort:true},
                { display: '机构名称', name: 'fundRasInsNm', width: 150, enabledSort:true},
	            { display: '业务模式', name: 'bizTypCdNm', minWidth: 140 , enabledSort:true},
	            { display: '项目状态', name: 'prjStsCdNm', minWidth: 100 , enabledSort:true},
	             { display: '申请单号', name: 'pNo', minWidth: 140 , 
	              	render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
            			if(value&&value!="null"){
            				if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_CAR){
		            		    h+='<a href="javascript:commShowFlowForCarBiz(';
            				}else{
		            		    h+='<a href="javascript:commShowFlow(';
            				}
	            		    h+="'"+rowdata.pInstId+"',";
	            		    h+="'"+rowdata.prjStsCd+"',";
	            		    h+="'"+rowdata.id+"'";
	            		    h+=')">'+value+'</a>'
            			}
                        return h;
            		},
	            	enabledSort:true}, 
	            { display: '数据来源', name: 'dsCdNm', minWidth: 100 , enabledSort:true},
	            { display: '创建时间', name: 'crtTm', minWidth: 100 , render:renderDate, enabledSort:true},
	            getOptColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        delayLoad:true,
	        rownumbers:true/* ,
	        onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	  
	 //   initOrgTree();
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["crtTm"] = $("#crtTm").val();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	
	    var form = new liger.get("searchBar");
        var data = form.getData();
        data["crtTm"] = $("#crtTm").val();
        for (name in data){
           grid.setParm(name,data[name]);
        };
        data["splId"]=_splId;
        data["lnkCompId"]=lnkCompId;
        if(StringUtils.isNotEmpty(_cstId)){
        	 data["cstId"]=_cstId;
		}
        grid.reload();
	    $("#pageloading").hide();
	
	});
	
	//获取操作列
	function getOptColumn(){
		var column = {
                display: '操作',
                isSort: false,
                width: 200,
                align:'left',
                render: function (rowdata, rowindex, value){
                	 var h="";
                	 if(rowdata.isDel!=1){
                            h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
                            h+="'"+rowdata.id+"'";
                            h+=')"><i class="sqBtnIco_7"></i>删除</a>'
                	 }
                	 if(cancelInsCreditList && cancelInsCodeCreditList){
                        if (cancelInsCodeCreditList.indexOf(rowdata.insCode) != -1) {
                            h+='<a class="sq-button-hasicon" href="javascript:cancelInsCreditBtn(';
                            h+="'"+rowdata.id+"'";
                            h+=')"><i class="sqBtnIco_4"></i>撤销资方授信</a>'
                        }
                     }
                    return h;
                }
            };
		return column;
	}
	//显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/project/audit/toAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	//乘用车流程
    function commShowFlowForCarBiz(_pInstId, _audStsCd, _businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/project/audit/toCarBizAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//删除所选项目信息
	function removeBtn(id){
		var _ids = [];
			_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjbscinfo/removePassAndIngPrjBscInfoByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
	}

	//调用撤销资方授信接口
	function cancelInsCreditBtn(id){
        $.ligerDialog.confirm("是否确认撤销资方授信?", function (flag) {
            if(flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:'id='+id,
                url: '<%=path%>/project/prjbscinfo/cancelInsCredit.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

	function detailBtn(id){
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		
		var id = selectedRows[0].id; */
		var fromPrjFlag = true;
		var detailFlag = true;
		
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		
		Add_navTab('tab_project_detail'+id,'项目详情','<%=path%>/project/prjbscinfo/toModifyPage.do?fromPrjFlag='+fromPrjFlag+'&&id='+id+'&&detailFlag='+detailFlag);
	}
	
	
  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				prjNm:" ",
				cstNm:" ",
				prjTypCd:" ",
				bizTypCd:" ",
				prjStsCd:" ",
				orgCd:" ",
				lsCntNo:" ",
				cstMgrNm:"",
				cntTypCd:" "
			 });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    }
	}
	
</script>

</body>
</html>